package com.qckj.amz.controller;

import com.qckj.amz.domain.Order;
import com.qckj.amz.service.IOrderService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 订单信息Controller
 *
 * @author luchuan
 * @since 1.0 2021-11-26
 */
@RestController
@RequestMapping("/amz/order")
public class OrderController extends BaseController {
    @Autowired
    private IOrderService orderService;

    /**
     * 查询订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('amz:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(Order order) {
        Page<Order> page = orderService.findOrderPage(order);
        return getDataTable(page);
    }

    /**
     * 导出订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('amz:order:export')")
    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Order order) {
        List<Order> list = orderService.findOrderList(order);
        ExcelUtil<Order> util = new ExcelUtil<>(Order.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
        return AjaxResult.success(orderService.findById(orderId));
    }

    /**
     * 新增订单信息
     */
    @PreAuthorize("@ss.hasPermi('amz:order:add')")
    @Log(title = "订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Order order) {
        orderService.save(order);
        return AjaxResult.success();
    }

    /**
     * 修改订单信息
     */
    @PreAuthorize("@ss.hasPermi('amz:order:edit')")
    @Log(title = "订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Order order) {
        orderService.save(order);
        return AjaxResult.success();
    }

    /**
     * 删除订单信息
     */
    @PreAuthorize("@ss.hasPermi('amz:order:remove')")
    @Log(title = "订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        orderService.deleteByIds(Arrays.asList(orderIds));
        return AjaxResult.success();
    }
}
